﻿$(function () {
    // Document.ready -> link up remove event handler 
    $(".RemoveLink").click(function () {
        //get the id from the link
        var recordToDelete = $(this).attr("data-id");

        if (recordToDelete != "") {
            //perform the ajax post
            $.post("/shoppingcart/removefromcart", { "id": recordToDelete },
                function (data) {
                    //success requests get here 
                    //update the page elements
                    if (data.ItemCount == 0) {
                        $('#row-' + data.DeleteId).fadeOut('slow');
                    } else {
                        $('#item-count-' + data.DeleteId).text(data.ItemCount);
                    }

                    $('#cart-total').text(data.CartTotal);
                    $('#update-message').text(data.Message);
                    $('#cart-status').text('Cart (' + data.CartCount + ')');
                });
        }
    });
});   
